<template>
  <div>
    <!-- 头部区域 -->
    <div class="page-header">
      <div class="title-section">
        <h1 class="page-title">订单管理</h1>
        <h1 class="page-title">总数: <span style="color: #c51d1d;">{{total}}</span></h1>
        <h1 class="page-title">今日导入: <span  style="color: #1021dc;">{{allData.today_count}}</span></h1>
      </div>
    </div>

    <!-- 搜索区域 -->
    <div class="search_box">
      <el-form ref="searchFormRef" :model="queryInfo" label-width="120px" class="search-box">
        <el-row :gutter="24">
          <el-col :span="6">
            <el-form-item prop="phone" label="号码搜索:">
              <el-input size="large" v-model.trim="queryInfo.phone" placeholder="搜索号码" :prefix-icon="Search"
                        @change="searchTable"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="phone" label="导入人信息账号:">
              <el-input size="large" v-model.trim="queryInfo.account" placeholder="搜索导入人信息账号" :prefix-icon="Search"
                        @change="searchTable"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="flex justify-end align-center">
              <el-button type="info" :icon="RefreshRight" size="large" @click="resetTable">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <!-- 表格区域 -->
    <div class="margin-top">
      <el-table ref="multipleTableRef" :data="listData" style="width: 100%">
        <el-table-column type="selection" width="55" />
        <el-table-column property="id" label="ID"></el-table-column>
        <el-table-column property="phone" label="号码"></el-table-column>
        <el-table-column label="导入人信息" width="150">
          <template #default="scope">
            <div>ID：{{ scope.row.userDataWithOne?.id }}</div>
            <div>账号：{{ scope.row.userDataWithOne?.phone }}</div>
            <div>昵称：{{ scope.row.userDataWithOne?.user_name }}</div>
          </template>
        </el-table-column>


        <el-table-column property="create_time" label="创建时间"></el-table-column>
      </el-table>
    </div>

    <!-- 分页区域 -->
    <div class="margin-top">
      <Pagination :total="total" @change="changePage" />
    </div>

    <!-- 产品表单模态框 -->
    <ProductFormModal v-model:visible="productModalVisible" :productData="currentProduct" :isEdit="isEditMode"
                      @submit="handleProductSubmit" />

    <!-- 添加价格弹窗 -->
    <ProductPriceFormModal ref="productPriceFormModalRef" @reload="searchTable" />
  </div>
</template>

<script lang="ts" setup>
  import { ref,onMounted } from 'vue'
  import useTableHook from '@/hooks/useTableHook'
  import { FansAdminPhoneListApi } from '@/api/index'
  import { RefreshRight } from '@element-plus/icons-vue'
  import ProductFormModal from '@/components/admin/merchants/ProductFormModal.vue'
  import ProductPriceFormModal from '@/components/admin/merchants/ProductPriceFormModal.vue'
  import Pagination from '@/components/admin/Pagination.vue'



  const queryInfo = ref({
    order_no: '',
    dates: [],
    start_time: '',
    end_time: '',
    status: '',
    page: 1,
    limit: 10,
  })

  const searchFormRef = ref<FormInstance>()

  // 重置表格
  const resetTable = () => {
    searchFormRef.value.resetFields()

    queryInfo.value.start_time = ''

    queryInfo.value.end_time = ''

    searchTable()
  }

  onMounted(() => {
    initTable()
  })

  const {
    total,
    listData,
    allData,
    searchTable,
    initTable,
    changePage,
  } = useTableHook(queryInfo.value, FansAdminPhoneListApi)

</script>

<style lang="scss" scoped>
  /* 头部区域样式 */
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
  }

  .title-section {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .page-title {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
    color: #2c3e50;
  }

  .merchant-name {
    color: #e74c3c;
  }

  .back-link {
    display: inline-flex;
    align-items: center;
    font-size: 14px;
    color: #7f8c8d;
    text-decoration: none;
    transition: color 0.3s;
    margin-top: 5px;
  }

  .back-link:hover {
    color: #e74c3c;
  }

  .back-link i {
    margin-right: 5px;
  }

  .header-actions {
    display: flex;
    gap: 10px;
  }

  .btn-primary {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-weight: 600;
    transition: background-color 0.3s;
  }

  .btn-primary:hover {
    background-color: #c0392b;
  }

  .btn-primary i {
    margin-right: 5px;
  }
</style>
